package com.ruoyi.classroom.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.classroom.domain.classroom;
import com.ruoyi.classroom.service.IclassroomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 教学资源管理Controller
 * 
 * @author chenxl
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/classroom/classroom")
public class classroomController extends BaseController
{
    @Autowired
    private IclassroomService classroomService;

    /**
     * 查询教学资源管理列表
     */
   // @PreAuthorize("@ss.hasPermi('classroom:classroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(classroom classroom)
    {
        startPage();
        List<classroom> list = classroomService.selectclassroomList(classroom);
        return getDataTable(list);
    }
    /**
     * 查询教学资源管理列表
     */
    // @PreAuthorize("@ss.hasPermi('classroom:classroom:list')")
    @GetMapping("/lists")
    public List<classroom> lists(classroom classroom)
    {
        System.out.println("lists查询参数：" + classroom);
        List<classroom> list = classroomService.selectclassroomList(classroom);
        System.out.println("lists查询结果：" + list);
        return list;
    }

    /**
     * 导出教学资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('classroom:classroom:export')")
    @Log(title = "教学资源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, classroom classroom)
    {
        List<classroom> list = classroomService.selectclassroomList(classroom);
        ExcelUtil<classroom> util = new ExcelUtil<classroom>(classroom.class);
        util.exportExcel(response, list, "教学资源管理数据");
    }

    /**
     * 获取教学资源管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('classroom:classroom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(classroomService.selectclassroomById(id));
    }

    /**
     * 新增教学资源管理
     */
    @PreAuthorize("@ss.hasPermi('classroom:classroom:add')")
    @Log(title = "教学资源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody classroom classroom)
    {
        classroom.setId(IdUtils.fastSimpleUUID());
        return toAjax(classroomService.insertclassroom(classroom));
    }

    /**
     * 修改教学资源管理
     */
    @PreAuthorize("@ss.hasPermi('classroom:classroom:edit')")
    @Log(title = "教学资源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody classroom classroom)
    {
        return toAjax(classroomService.updateclassroom(classroom));
    }

    /**
     * 删除教学资源管理
     */
    @PreAuthorize("@ss.hasPermi('classroom:classroom:remove')")
    @Log(title = "教学资源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(classroomService.deleteclassroomByIds(ids));
    }

    /**
     *导入课程信息
     */
    @PostMapping("/importClassroomData")
    @ResponseBody
    public AjaxResult importClassroomData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<classroom> util = new ExcelUtil<classroom>(classroom.class);
        List<classroom> classroomList = util.importExcel(file.getInputStream());
        String message = classroomService.importclassroom(classroomList, updateSupport);
        return AjaxResult.success(message);
    }
}
